package com.touch.jgloo.owt;
import com.touch.jgloo.core.*;
import com.sun.opengl.util.texture.*;
/**
 * A JGLTile is a JGLQuad that is loaded from a tile sheet
 * @author Homicidal Monkey
 * @version 10.1.9
 * @since r419
 * @see com/touch/Licence
 * @deprecated Use JGLQuad instead since this does not support repeating the texture.
 *
 */
public class JGLTile extends JGLQuad
{
	public int sheet;
	private int x, y;	
	/**
	 * Sets the texture of the Tile
	 * @param texture Texture that the tile uses
	 * @since r461
	 */
	public final  void setTexture(final Texture texture)
	{
		final JGLPolygon polygon = this.getPolygon();
		polygon.setTexture(texture);
	}
	public final  Texture getTexture()
	{
		final JGLPolygon polygon = this.getPolygon();
		return polygon.getTexture();
	}
	/**
	 * Sets the Tile image as a sub-image of the tile's texture.
	 * @param xSource Left-most position of the tile's pixels
	 * @param ySource Top-most position of the tile'pixels
	 * @since r461
	 */
	public final  void setTile(final int xSource, final int ySource)
	{		
		this.x = xSource;
		this.y = ySource;		
		final JGLPolygon polygon = this.getPolygon();
		final float u1, u2, v1, v2;
		if(this.getTexture() == null)
			return;
		u1 = (xSource * 32f) / polygon.getTexture().getWidth();
		v1 = (ySource * 32f) / polygon.getTexture().getHeight();
		u2 = ((xSource + 1) * 32f) / polygon.getTexture().getWidth();
		v2 = ((ySource + 1) * 32f) / polygon.getTexture().getHeight();
		polygon.setUV(0, new JGLUV(u1, v1));
		polygon.setUV(1, new JGLUV(u2, v1));
		polygon.setUV(2, new JGLUV(u2, v2));
		polygon.setUV(3, new JGLUV(u1, v2));		
	}	
	public final int getY() {
		return this.y;
	}	
	public final int getX() {
		return this.x;
	}
}
